﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using VswService_V7.Utility;

namespace VswService_V7.DataBase.Tables.L3INTERFACE
{
    public class L3INTF_STRIP_DELETE
    {
        #region field
        public static readonly string tableName = "L3INTF_STRIP_DELETE";
        public static readonly string fd_eventNo = "EVENT_NO";
        public static readonly string fd_stripNo = "STRIP_NO";
        public static readonly string fd_batchNo = "BATCH_NO";
        public static readonly string fd_taskNo = "TASK_NO";
        public static readonly string fd_updateTime = "UPDATE_TIME";
        #endregion
        /// <summary>
        /// L3 deletes one strip on L2
        /// </summary>
        /// <param name="event_id"></param>
        public static void DeleteStripfromTask(string event_id)
        {
            try
            {
                string sqlStrip = string.Format("select * from {0} where {1}={2}", tableName, fd_eventNo, event_id);
                DataTable stripTable = OracleHelper.Exct_QueryTable(sqlStrip);
                if (stripTable != null && stripTable.Rows.Count >= 1)
                {
                    ExecuteDeleteStripfromTask(stripTable);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("L3INTF_STRIP_DELETE.DeleteStripfromTask", ex);
                throw (ex);
            }
        }
        private static void ExecuteDeleteStripfromTask(DataTable stripTable)
        {
            try
            {
                for (int i = 0; i < stripTable.Rows.Count; i++)
                {
                    string sqlStrip = string.Format("delete from {0} where {1}='{2}'",
                    STRIP_INFO.tableName, fd_stripNo, stripTable.Rows[i][fd_stripNo].ToString());
                    string l3infcEventsql = string.Format("update {0} set {1}={2} where {3}={4}", L3INTF_EVENT.tableName, L3INTF_EVENT.fd_eventStatus, "2", L3INTF_EVENT.fd_eventNo, stripTable.Rows[0][fd_eventNo].ToString());
                    List<string> sqlList = new List<string>();
                    sqlList.Add(sqlStrip);
                    sqlList.Add(l3infcEventsql);
                    OracleHelper.ExecuteSqlTran(sqlList);
                }
                LogHelper.WriteLog("L3INTF_STRIP_DELETE.ExecuteDeleteStripfromTask Success!");
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("L3INTF_STRIP_DELETE.ExecuteDeleteStripfromTask", ex);
                throw ex;
            }
        }
    }
}
